<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>北京联合大学</title>
</head>
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://at.alicdn.com/t/font_835526_f1lycael0ir.css">
<link rel="stylesheet" href="../../css/Initialization.css">
<link rel="stylesheet" href="../../css/commen.css">
<link rel="stylesheet" href="../../css/teachertask.css">
<body>
<div id="content">
    <div class="initer">
            <!-- 具体内容 -->
            <div class="bread">
                <div class="plain" th:text="${menu.menuname}">成立公司</div>
                <div class="plain">
                    <i class="iconfont icon-right"></i>
                </div>
                <div class="plain current"><a th:text="${smenu.menuname}" th:href="@{basicslist(mid=${menu.id},sid=${smenu.id},gradeid=${content.gradeid})}">单元知识点</a></div>
                <div class="plain">
                    <i class="iconfont icon-right"></i>
                </div>
                <div class="plain current" th:text="${smenu.menuname}+'管理'">单元知识点</div>
            </div>
            <div class="teacherform">
                <div class="teacherinput">
                    <span class="title">标题</span>
                    <input type="hidden" id="id" name="id" th:value="${content.id}">
                    <input type="hidden" id="mid" name="mid" th:value="${content.mid}"/>
                    <input type="hidden" id="sid" name="sid" th:value="${content.sid}"/>
                    <input type="hidden" id="gradeid" name="gradeid" th:value="${content.gradeid}"/>
                    <input type="text" id="title" name="title" placeholder="请输入标题" class="inputtitle" th:value="${content.title}">
                </div>
                <div class="teacherinput" th:if="${smenu.id != sortid}">
                    <input type="hidden" id="sort" name="sort" value="0"/>
                    <span class="title">附件上传 </span>
                    <input type="text" id="upattachments" name="upattachments" placeholder="请选择附件" class="fujian" th:value="${content.attachments}">
                    <div class="center-button">选择 <input type="file" class="file" id="attachments" name="attachments"/> </div>
                    <div class="center-button" onclick="upload()">上传 <i class="iconfont icon-shangchuan1"></i></div>
                </div>
                <div class="teacherinput" th:if="${smenu.id == sortid}">
                    <span class="title">步骤顺序</span>
                    <input type="text" id="sort" name="sort" placeholder="请输入步骤顺序" class="inputtitle" th:value="${content.sort}">
                </div>
                <div class="teacherinput teacherinputdetail">
                    <span class="title">详细内容</span>
                    <!-- <input type="text" placeholder="请输入标题"> -->
                    <div id="editor" placeholder="请输入详细内容" th:utext="${content.detail}">
                    </div>
                </div>
            </div>

            <div class="save">
                <div class="center-button" id="subBut">编辑</div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <div class="center-button" onclick="history.back();">返回</div>
            </div>
        </div>
</div>
<script src="../../js/jquery-3.4.1.min.js"></script>
<script src="../../js/commen.js"></script>
<script src="../../js/wangEditor.js"></script>
<script src="../../js/uploadFile.js"></script>
<script th:inline="javascript">
    var editor;
    window.onload = function(){
        // 富文本编辑器
        var E = window.wangEditor;
        editor = new E('#editor');
        // 或者 var editor = new E( document.getElementById('editor') )
        editor.create()
    };
    $(function(){
        $("#attachments").change(function () {
            $("#upattachments").val(getFileName($(this).val()));
        });
        $("#subBut").click(function(){
            var id = $("#id").val();
            var mid = $("#mid").val();
            var sid = $("#sid").val();
            var gradeid = $("#gradeid").val();
            var title = $("#title").val();
            var detail = editor.txt.html();
            var attachments = $("#upattachments").val();
            var sort = $("#sort").val();
            if(title.length == 0){
                alert("请输入标题");
                $("#title").focus();
                return false;
            }/*else if(attachments.length == 0){
                alert("请上传附件");
                $("#attachments").focus();
                return false;
            }*/else if(detail.length == 0){
                alert("请输入详细内容");
                $("#detail").focus();
                return false;
            }else{
                $.ajax({
                    type : "POST",
                    url : "toadd",
                    data : {id:id,mid: mid,sid: sid,gradeid:gradeid,sort:sort, title: title, detail: detail, attachments: attachments},
                    dataType : "json",
                    success : function(json) {
                        if(json.state == error){
                            alert(json.result);
                        }else{
                            alert("编辑成功");
                            location.href = "basicslist?mid="+mid+"&sid="+sid+"&gradeid="+gradeid;
                        }
                    },
                    error:function(msg){
                        alert("程序出错，请联系管理员");
                    }
                });
            }
        });
    });

    function upload() {
        var formData = new FormData();
        var mname = [[${menu.menuname}]];
        var sname = [[${smenu.menuname}]];
        var sid = $("#sid").val();
        formData.append("file", document.getElementById("attachments").files[0]);
        formData.append("mname", mname);
        formData.append("sname", sname);
        formData.append("sid", sid);
        $.ajax({
            url: "uploadContent",
            type: "POST",
            data: formData,
            contentType: false,
            processData: false,
            dataType:"json",
            success: function (data) {
                if(data.state == success){
                    $("#upattachments").val(data.data)
                }else if(data.state == error){
                    alert(data.result);
                }
            },
            error: function () {
                alert("上传失败！");
            }
        });
    }
</script>
</body>
</html>

